package offer;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 剑指 Offer 50. 第一个只出现一次的字符
 * </p>
 *
 * @author xiaozuolin
 * @date 2021/9/27 10:52
 */
public class Offer50 {

    public char firstUniqChar(String s) {
        Map<Character, Boolean> dic = new HashMap<>();
        char[] chars = s.toCharArray();
        for (char c : chars) {
            dic.put(c, !dic.containsKey(c));
        }
        for (char c : chars) {
            if (dic.get(c)) {
                return c;
            }
        }
        return ' ';
    }
}
